<?php
/**
 * Created by PhpStorm.
 * User: liujianlin
 * Date: 2017/5/17
 * Time: 9:15
 */

namespace app\controllers;

use yii;
use yii\web\Controller;
use app\components\EmailMarket;

class TestEmailController extends Controller
{
    public function test1(){
        echo 1;
    }

    public function actionDecrypt()
    {
        $email = new EmailMarket();
        $encryptEmail = '##bh1Q5omz0ZhuAQWnqnN3nlcv8b3Td4IgZfwWQ4Pc4o0=';

        $decryptEmail = $email->decryption($encryptEmail);
        var_dump($decryptEmail);
        exit();
    }

    public function actionEncrypt()
    {
        $email = new EmailMarket();
        
        $mothod = strtolower(Yii::$app->request->getMethod());
        $origEmail = Yii::$app->request->$mothod('email');

        $encryptEmail = $email->encryption($origEmail);
        var_dump($encryptEmail);
        exit();
    }
    
    
    public function actionIsEmail()
    {
        $email = new EmailMarket();
        $origEmail = 'liujianlin@globalegrow.com';

        $encryptEmail = $email->isEmail($origEmail);
        var_dump($encryptEmail);
        exit();
    }

    public function actionTest()
    {
        $gi = geoip_open(yii::$app->basePath . "/config/geoip/GeoIP.dat",GEOIP_STANDARD);

        echo geoip_country_code_by_addr($gi, "202.104.111.148") . "<br/>" ;
    }

    public function actionWriteLog()
    {
        file_put_contents(yii::$app->getRuntimePath() . "/logs/test.log",  date("Y-m-d H:i:s") . "测试\n", FILE_APPEND);
        echo "写入日志";
    }


    public function actionMysqlRead()
    {
        $sql = "select * from user_trendsgal limit 2";
        $result = yii::$app->db->createCommand($sql)->queryAll();
        echo "<pre>";
        print_r($result);
        echo "</pre>";
    }

    public function actionMysqlWrite()
    {
        $sql = "insert into redis_log(admin_id, admin_name, action, action_key_type, action_key_name, add_time, detail, ip)
                values(1, 'test', 'del', 'hash', 'testKey', 11111, 'only for test', 123456)";
        $result = yii::$app->db->createCommand($sql)->execute();
        var_dump($result);
    }

    public function actionCurl()
    {
        $url = "http://www.baidu.com";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
        $result = curl_exec($ch); //返回结果
        curl_close($ch);
        echo $result;
    }

    public function actionHttpHost()
    {
        echo "http host[{$_SERVER['HTTP_HOST']}]";
    }

}
